<template>
  <RouterView />
</template>

<script lang="ts" setup>
import { isLoginAPI } from "@/http/api/user";
import { useRouter } from "vue-router";
import { getCookie } from "@/utils/cookieUtil";
const router = useRouter();

router.beforeEach((to, from, next) => {
  if (to.path != '/' && !getCookie("token")) {
    next("/");
  } else {
    next();
  }
});

// 页面初始化
isLoginAPI().then((res) => {
  // 判断登录是否过期
  if (res.code == 401) {
    document.cookie = '';
  }
});
</script>

<style>
* {
  font-family: "Cormorant Garamond", serif;
}
</style>
